package com.shop.controller;


import com.shop.entity.Reduction;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import com.shop.service.ReductionService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 满减表
 * <p>
 * 陈炼豪(Reduction)表控制层
 *
 * @author makejava
 * @since 2020-11-25 14:42:08
 */
@Validated
@RestController
@AllArgsConstructor
public class ReductionController {
    /**
     * 服务对象
     */
    private final ReductionService reductionService;

    @GetMapping("getReductionByMerchantId")
    public Rsp getReductionByMerchantId(Integer id){
        return reductionService.getReductionByMerchantId(id);
    }

    /**
     * @author Clh
     * @description 查询店铺的满减信息
     * @date  2020/11/26 11:49
     * @param pageParam 实体类
     * @param merchantId 店铺id
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("getReduction")
    public Rsp getReduction(@RequestBody PageParam<Reduction> pageParam,
                        @RequestHeader Integer merchantId){

        return Rsp.success(reductionService.getReduction(pageParam,merchantId));
    }
    /**
     * @author Clh
     * @description 添加店铺满减信息
     * @date  2020/11/26 14:39
     * @param reduction
     * @param merchantId
     * @param userId
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("insertSelective")
    public Rsp insertSelective(@RequestBody Reduction reduction,
                               @RequestHeader Integer merchantId,
                               @RequestHeader Integer userId){
        System.out.println(reduction);
       return reductionService.insertSelective(reduction,merchantId,userId);
    }
    /**
     * @author Clh
     * @description
     * @date  2020/11/26 15:05
     * @param reduction
     * @return com.shop.model.vo.Rsp
    **/
    @PostMapping("deleteById")
    public Rsp deleteById(@RequestBody Reduction reduction){
       return reductionService.deleteById(reduction);
    }

    @PostMapping("updateById")
    public Rsp updateById(@RequestBody Reduction reduction,
                          @RequestHeader Integer userId){

        return reductionService.updateById(reduction,userId);
    }
}
